const crypto = require('crypto');

function decryptAlipayData ({
	encryptedData
}) {
	const oauthConfig = this.configUtils.getOauthConfig({
	  provider: 'alipay'
	})
	let key = oauthConfig.secretKey;
	let crypted = encryptedData; // 密文
	crypted = Buffer.from(crypted, 'base64').toString('binary');
	key = Buffer.from(key, 'base64');
	const iv = Buffer.alloc(16, 0)
	const decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
	let decoded = decipher.update(crypted, 'binary', 'utf8');
	decoded += decipher.final('utf8');
	try {
		decoded = JSON.parse(decoded);
		return decoded;
	} catch(e) {
		return decoded;
	}
}

module.exports = {
  decryptAlipayData,
}

